﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using NHibernateDemo.Core;
using NHibernateDemo.DAL;

[TestFixture]
public class BuildDataBase : BaseRepositoryFixture<IRepository<Ninja, int>>
{    
    [SetUp]
    public void CreateSchema()
    {
        _Repository = new NHibernateDemo.DAL.Repository<Ninja, int>();

        Configuration cfg = new NHibernate.Cfg.Configuration();
        SchemaExport exporter = new SchemaExport(cfg.Configure());
        exporter.Create(true, true);
        exporter.Execute(false, true, false, true);           
    }

    [Test]
    public void PopulateData()
    {
        Ninja raphael = new Ninja { Name = "Raphael", HitPoints = 2, Address = new Address{ City = "Ann Arbor", State = "MI", Zip = "48104" } };
        Ninja leonardo = new Ninja { Name = "Leonardo", HitPoints = 5};
        Ninja bruce = new Ninja { Name = "Bruce Lee", HitPoints = 120};

        
        raphael.Weapons.Add(new Weapon { Damage = 10, Name = "Sai", Quantity = 2 });
        bruce.Weapons.Add(new Weapon { Damage=5, Name="Fists", Quantity=2 });
        bruce.Weapons.Add(new ThrowableWeapon { Damage = 9, Name = "Throwing Stars", Quantity = 20, Weight = 9, Poison = false });
        leonardo.Weapons.Add(new Weapon { Damage = 9, Name = "Katana", Quantity = 20 });
        
        _Repository.Save(raphael);
        _Repository.Save(leonardo);
        _Repository.Save(bruce);
        _Repository.Flush();
    }
}